package com.gp.zh.controller;

import com.gp.entity.Area;
import com.gp.entity.Result;
import com.gp.zh.service.AreaService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/area")
@CrossOrigin
public class AreaController {
    @Resource
    private AreaService areaService;

    /**
     * 通过负责人id获取区域列表
     * @param leaderId
     * @return
     */
    @GetMapping("/getAreaList/{leaderId}")
    public Result getAreaList(@PathVariable String leaderId) {
        List<Area> areaList = areaService.getAreaList(leaderId);
        return Result.success(areaList);
    }

    /**
     * 工厂通过areId获取工厂下面的单元列表
     * @param areaId
     * @return
     */
    @GetMapping("/getUnitList/{areaId}")
    public Result getUnitList(@PathVariable int areaId) {
        List<Area> unitList = areaService.getUnitList(areaId);
        return Result.success(unitList);
    }

    /**
     * 单元通过faAreaId获取单元所在的工厂
     * @param faAreaId
     * @return
     */
    @GetMapping("/getFactoryList/{faAreaId}")
    public Result getFactoryList(@PathVariable int faAreaId) {
        List<Area> factoryList = areaService.getFactoryList(faAreaId);
        return Result.success(factoryList);
    }

    /**
     * 单元通过unitId获取生产线列表
     * @param unitId
     * @return
     */
    @GetMapping("/getLineList/{unitId}")
    public Result getLineList(@PathVariable int unitId) {
        List<Area> lineList = areaService.getLineList(unitId);
        return Result.success(lineList);
    }

    /**
     * 生产线通过faLineId获取生产线所在的单元
     * @param faLineId
     * @return
     */
    @GetMapping("/getFaUnit/{faLineId}")
    public Result getFaUnit(@PathVariable int faLineId) {
        List<Area> faUnit = areaService.getFaUnit(faLineId);
        return Result.success(faUnit);
    }
}
